

import threading
from time import sleep

# 线程锁
lock = threading.Lock()

# 线程本地变量 ,线程独有
local = threading.local()

num = 0


def run(num):
    num = num + 1
    # num = num - 1
    return num


def func(str):
    global num

    local.x = num
    for i in range(1000000):
        local.x = run(local.x)
    print("当前线程 %s ,与 num的值 %d" % (threading.current_thread().name, local.x))


if __name__ == "__main__":
    t1 = threading.Thread(target=func, args=('ok',))
    t2 = threading.Thread(target=func, args=('ok',))

    t1.start()
    t2.start()

    t1.join()
    t2.join()

    print("当前的num =", num)

